<template>
  <div class="components-container">
    <!--  核心区域  -->
    <div class="wrapper">
      <!--左边-->
      <div class="left">
        <div class="left-all" v-for="(item,index) in roomstatusList" :key="index">
          <div class="roomTitle">
            <div class="toptitle" @click="updateDescriptionsTitle(item.roomInfo.description)">
              {{ item.roomInfo.description }}
            </div>
          </div>
          <div class="btn-room-out" v-if="item.roomsDetails.length === 0">
            <el-empty :image-size="100" description="暂无房源，请先添加！"></el-empty>
          </div>
          <div class="btn-room" v-for="(roomDetail,roomIndex) in roomstatusList[index].roomsDetails" :key="roomIndex">
            {{ roomDetail.roomNumber }}
          </div>
        </div>
      </div>
      <!--右边-->
      <div class="right">
        <!--        状态信息-->
        <div class="rightRoomStatus-info">
            <div class="rightRoomStatus-top" >
              <el-tag color="#67C23A"></el-tag>
              <div class="p-det"><p>空闲</p></div>
              <el-tag color="#E6A23C"></el-tag>
              <div class="p-det"><p>未清洁</p></div>
            </div>
            <div class="rightRoomStatus-top" >
              <el-tag color="#F56C6C"></el-tag>
              <div class="p-det"><p>已入住</p></div>
              <el-tag color="#909399"></el-tag>
              <div class="p-det"><p>已预订</p></div>
            </div>
        </div>
        <!--        房源信息-->
        <div class="rightRoom-info">
          <h3>客房信息</h3>
          <div id="descriptions-info">
            <el-descriptions class="margin-top" :title="descriptionsTitle" :column="1" :size="size" border>
              <template slot="extra">
                <el-button type="primary" size="small">操作</el-button>
              </template>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-user"></i>
                  用户名
                </template>
                kooriookami
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-mobile-phone"></i>
                  手机号
                </template>
                18100000000
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-location-outline"></i>
                  居住地
                </template>
                苏州市
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-tickets"></i>
                  备注
                </template>
                <el-tag size="small">学校</el-tag>
              </el-descriptions-item>
              <el-descriptions-item>
                <template slot="label">
                  <i class="el-icon-office-building"></i>
                  联系地址
                </template>
                江苏省苏州市吴中区吴中大道 1188 号
              </el-descriptions-item>
            </el-descriptions>
          </div>
        </div>
      </div>
    </div>

    <!--    分页   -->
    <!--    <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />-->

    <!-- 添加或修改客房状态对话框 -->
    <!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="客房ID" prop="roomId">
              <el-input v-model="form.roomId" placeholder="请输入客房ID"/>
            </el-form-item>
            <el-form-item label="房间号" prop="roomNumber">
              <el-input v-model="form.roomNumber" placeholder="请输入房间号"/>
            </el-form-item>
            <el-form-item label="日期" prop="date">
              <el-date-picker clearable
                              v-model="form.date"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="创建者ID" prop="createdBy">
              <el-input v-model="form.createdBy" placeholder="请输入创建者ID"/>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>-->
  </div>
</template>

<script>
import {listRoomstatus, getRoomstatus, delRoomstatus, addRoomstatus, updateRoomstatus} from "@/api/business/roomstatus";
import {red} from "chalk";

export default {
  name: "Roomstatus",
  dicts: ['hbms_roomcheck_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客房状态表格数据
      roomstatusList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roomId: null,
        roomNumber: null,
        date: null,
        outDate: null,
        userId: null,
        status: null,
        createdBy: null
      },
      descriptionsTitle: '枫林晚酒店管理系统',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        roomId: [
          {required: true, message: "客房ID不能为空", trigger: "blur"}
        ],
        roomNumber: [
          {required: true, message: "房间号不能为空", trigger: "blur"}
        ],
        date: [
          {required: true, message: "日期不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    red,
    /** 查询客房状态列表 */
    getList() {
      this.loading = true;
      listRoomstatus(this.queryParams).then(response => {
        this.roomstatusList = response.data;
        console.log(this.roomstatusList)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        roomStatusId: null,
        roomId: null,
        date: null,
        status: null,
        createdBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.roomStatusId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客房状态";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const roomStatusId = row.roomStatusId || this.ids
      getRoomstatus(roomStatusId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改客房状态";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.roomStatusId != null) {
            updateRoomstatus(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRoomstatus(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roomStatusIds = row.roomStatusId || this.ids;
      this.$modal.confirm('是否确认删除客房状态编号为"' + roomStatusIds + '"的数据项？').then(function () {
        return delRoomstatus(roomStatusIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/roomstatus/export', {
        ...this.queryParams
      }, `roomstatus_${new Date().getTime()}.xlsx`)
    },
    // 改变客房信息中的标题
    updateDescriptionsTitle(description) {
      this.descriptionsTitle = description;
    }
  }
};
</script>
<style lang="scss" scoped>
.wrapper {
  width: 100%;
  display: flex;
}

.left {
  width: 75%;
  background-color: rgba(225, 187, 187, 0.96);

  /*display: grid;
  !* 自动适应宽度，最小宽度为 100px *!
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  grid-gap: 10px; !* 设置盒子之间的间隔 *!*/

  display: flex;
  flex-wrap: wrap; /* 允许子元素换行 */
  justify-content: flex-start; /* 从左到右排列 */
  flex-direction: column;
  align-items: flex-start; /* 顶部对齐 */
  border-radius: 5px;

}

.left .left-all {
  display: flex;
  flex-wrap: wrap;
  //justify-content: flex-start;
}

.roomTitle {
  display: flex;
  margin-top: 15px;
  margin-left: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  width: 100%;
  height: 25px;
  font-size: 18px;
  //justify-items: flex-start;
  justify-content: space-between;
  cursor: pointer; /* 设置鼠标悬停样式*/
}

.left .left-all .roomTitle .toptitle {
  background-color: transparent;
  color: #852f3e;
}

.left .left-all .roomTitle .topBtn {
  background-color: #1c84c6;
  font-size: 15px;
}

.btn-room {
  background-color: #67C23A;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  align-content: center;
  padding: 10px;
  text-align: center;
  margin-bottom: 10px;
  margin-right: 10px;
  margin-left: 13px;
  word-wrap: break-word; /* 当单词过长时自动换行 */
  width: 90px;
  height: 90px;
  border-radius: 5px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  cursor: pointer; /* 设置鼠标悬停样式*/
}

.btn-room-out {
  width: 950px;
  height: 200px;
  display: flex;
  align-content: center;
  justify-content: center;
  font-size: 15px;
  color: #ee1313;

}

/*右边*/
.right {
  margin-left: 15px;
  width: 25%;
  background-color: rgba(122, 248, 248, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 5px;
}

.rightRoomStatus-info {
  display: flex;
  flex-direction: column;
  align-content: flex-start;
  justify-content: space-between;
  height: 20%;
  margin-top: 40px;
  font-size: 13px;
  cursor: pointer; /* 设置鼠标悬停样式*/
}

.rightRoomStatus-info .rightRoomStatus-top{
  display: flex;
  flex-direction: row;
  flex: 1;
  justify-content: space-between;
  align-content: center;

}
.rightRoomStatus-info .p-det {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-content: flex-start;
  justify-content: space-between;
  line-height: 3px;
  margin-left: 10px;
  margin-right: 20px;
}

.rightRoom-info {
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: center;
  height: 80%;
  margin-bottom: 15px;
  color: #00afff;
}
.rightRoom-info h3{
  display: flex;
  margin-bottom: 10px;
  align-content: center;
  justify-content: center;
}
#descriptions-info{
  margin: 10px;
}

</style>
